package com.driver.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.driver.manage.domain.ImitatePosition;
import com.ruoyi.system.api.model.LoginDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.driver.manage.domain.TbDriver;
import com.driver.manage.service.ITbDriverService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 司机Controller
 * 
 * @author ruoyi
 * @date 2023-06-24
 */
@RestController
@RequestMapping("/driver")
public class TbDriverController extends BaseController
{
    @Autowired
    private ITbDriverService tbDriverService;

    /**
     * 查询司机列表
     */
    @RequiresPermissions("manage:driver:list")
    @GetMapping("/list")
    public TableDataInfo list(TbDriver tbDriver)
    {
        startPage();
        List<TbDriver> list = tbDriverService.selectTbDriverList(tbDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机列表
     */
    @RequiresPermissions("manage:driver:export")
    @Log(title = "司机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDriver tbDriver)
    {
        List<TbDriver> list = tbDriverService.selectTbDriverList(tbDriver);
        ExcelUtil<TbDriver> util = new ExcelUtil<TbDriver>(TbDriver.class);
        util.exportExcel(response, list, "司机数据");
    }

    /**
     * 获取司机详细信息
     */
    @RequiresPermissions("manage:driver:query")
    @GetMapping(value = "/{driverId}")
    public AjaxResult getInfo(@PathVariable("driverId") Integer driverId)
    {
        return success(tbDriverService.selectTbDriverByDriverId(driverId));
    }

    /**
     * 新增司机
     */
    @RequiresPermissions("manage:driver:add")
    @Log(title = "司机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDriver tbDriver)
    {
        return toAjax(tbDriverService.insertTbDriver(tbDriver));
    }

    /**
     * 修改司机
     */
    @RequiresPermissions("manage:driver:edit")
    @Log(title = "司机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDriver tbDriver)
    {
        return toAjax(tbDriverService.updateTbDriver(tbDriver));
    }

    /**
     * 删除司机
     */
    @RequiresPermissions("manage:driver:remove")
    @Log(title = "司机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{driverIds}")
    public AjaxResult remove(@PathVariable String[] driverIds)
    {
        return toAjax(tbDriverService.deleteTbDriverByDriverIds(driverIds));
    }

    /**
     * 注册
     * @param loginDriver
     * @return
     */
    @PostMapping("register")
    public LoginDriver register1(@RequestBody LoginDriver loginDriver){
        return tbDriverService.register(loginDriver);
    }

    /**
     * 手机号查看是否存在信息
     * @param driverPhone
     * @return
     */
    @GetMapping("/getList/{driverPhone}")
    public TbDriver register(@PathVariable("driverPhone") String driverPhone){
        TbDriver list = tbDriverService.getList(driverPhone);
        return list;
    }

    /**
    * @description: TODO
    * @author 苏鹏锋
     * 查询模拟路径下拉框
    * @date 2023/7/2 0002 19:56
    * @version 1.0
    */
    @PostMapping("/findByIm")
    public TableDataInfo findByIm(){
        startPage();
        List<ImitatePosition> list = tbDriverService.findByIm();
        return getDataTable(list);
    }
}
